import express from 'express';
import * as deliveryController from './delivery.controller';
import { fileInterceptor, fileProcessor } from './delivery.middleware';
import { validateLoginData, authGuard, userGuard } from '../auth/auth.middleware';

const router = express.Router();

/**
 * 获取内容
 */
router.get('/delivery', userGuard, deliveryController.index);

/**
 * 获取内容(按 ID)
 */
router.get('/delivery/:postId', userGuard, deliveryController.deliveryDetail);

/**
 * 按关键字查询（模糊查询）
 */
router.get('/getDeliveryByKey', deliveryController.selectByKey);

/**
 * 创建内容
 */
router.post('/delivery', authGuard, deliveryController.store);

/**
 * 更新内容
 */
router.patch('/delivery/:postId', deliveryController.update);

/**
 * 删除内容
 */
router.delete('/delivery/:postId', authGuard, deliveryController.destroy);
router.post('/deliveryDestroy', authGuard, deliveryController.destroy);

/**
 * 修改状态
 */
router.patch('/deliveryStatus', deliveryController.status);

/**
 * 上传文件
 */
router.post('/deliveryFiles', authGuard, fileInterceptor, fileProcessor, deliveryController.uploads);

/**
 * 文件服务
 */
router.get('/deliveryFiles/:fileId/serve', deliveryController.serve);

/**
 * 获取文件 ID
 */
router.post('/getDeliveryFilesId', deliveryController.getFileName);

/**
 * 导出路由
 */
export default router;
